package com.apply;

import com.bean.*;
import com.enums.ConsoleFontStyleEnum;
import com.enums.FigureBeanInstance;
import org.fusesource.jansi.Ansi;

//图案实例
public class FigureInstanceBuilderOk {
    /**
     * 五彩斑斓的女人
     */
    private static FigureBean colorfulWomen() {
        FigureBean belle1 = FigureBeanInstance.BELLE1;
        for (LineMessageBean lineMessageBean : belle1.getLineMessageBeans()) {
            HandleFunction handleFunction = charBeans -> {
                for (int i = 0; i < charBeans.size(); i++) {
                    CharBean charBean = charBeans.get(i);
                    if (charBean.getCharValue() != ' ') {
                        if (i % 2 == 0) {
                            charBean.setColor(new CharColor(Ansi.Color.BLUE, new FontStyleBean(ConsoleFontStyleEnum.Color.RED)));
                        } else {
                            charBean.setColor(new CharColor(Ansi.Color.RED, new FontStyleBean(ConsoleFontStyleEnum.Color.BLUE)));
                        }
                    } else {
                        charBean.setColor(new CharColor());
                    }
                }
            };
            lineMessageBean.setHandleFunction(handleFunction);
        }
        return belle1;
    }

    /**
     * 龙图腾
     */
    private static FigureBean dragonTotem() {
        FigureBean dragon1 = FigureBeanInstance.DRAGON1;
        HandleFunction handleFunction = charBeans -> {
            for (CharBean charBean : charBeans) {
                if (charBean.getCharValue() == '1') {
                    charBean.setColor(new CharColor(Ansi.Color.WHITE, new FontStyleBean(ConsoleFontStyleEnum.Color.WHITE)));
                } else if (charBean.getCharValue() == '0') {
                    charBean.setColor(new CharColor(Ansi.Color.RED, new FontStyleBean(ConsoleFontStyleEnum.Color.RED)));
                }
            }
        };
        for (LineMessageBean lineMessageBean : dragon1.getLineMessageBeans()) {
            lineMessageBean.setHandleFunction(handleFunction);
        }
        return dragon1;
    }

    /**
     * 红色的龙
     */
    private static FigureBean dragonRed() {
        FigureBean dragon2 = FigureBeanInstance.DRAGON2;
        HandleFunction handleFunction = charBeans -> {
            for (CharBean charBean : charBeans) {
                if (charBean.getCharValue() != ' ') {
                    charBean.setColor(new CharColor(Ansi.Color.RED, new FontStyleBean(ConsoleFontStyleEnum.Color.RED)));
                }
            }
        };
        for (LineMessageBean lineMessageBean : dragon2.getLineMessageBeans()) {
            lineMessageBean.setHandleFunction(handleFunction);
        }
        return dragon2;
    }

    /**
     * 发光的悟空
     */
    private static FigureBean glowingGoku() {
        FigureBean dragonBallGoku2 = FigureBeanInstance.DragonBall_Goku2;
        HandleFunction handleFunction = charBeans -> {
            for (CharBean charBean : charBeans) {
                if (charBean.getCharValue() != ' ') {
                    charBean.setColor(new CharColor(Ansi.Color.RED, new FontStyleBean(ConsoleFontStyleEnum.Color.RED)));
                }
            }
        };
        for (LineMessageBean lineMessageBean : dragonBallGoku2.getLineMessageBeans()) {
            lineMessageBean.setHandleFunction(handleFunction);
        }
        return dragonBallGoku2;
    }
}